import 'package:earclean/app/config/colors.dart';
import 'package:earclean/app/modules/widget/app_bar_widget.dart';
import 'package:earclean/app/modules/widget/load_network_image_widget.dart';
import 'package:earclean/app/modules/widget/multi_row_input_widget%20copy.dart';
import 'package:earclean/app/modules/widget/star_rating_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import 'package:get/get.dart';

import '../controllers/evaluate_controller.dart';

class EvaluateView extends GetView<EvaluateController> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBarWidget(
        titleStr: '评价',
        actions: [
          TextButton(
              onPressed: controller.toAdd,
              child: const Text(
                " 发表",
                style: TextStyle(
                    fontWeight: FontWeight.w500,
                    fontSize: 14,
                    color: ColorConfig.subtitle_text),
              ))
        ],
      ),
      body: SingleChildScrollView(
        child: Column(
          children: [
            itemWidget(),
            const SizedBox(height: 10),
            Container(
              margin: const EdgeInsets.symmetric(
                horizontal: 15,
              ),
              padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 5),
              color: ColorConfig.white,
              child: Row(
                children: [
                  Text('评分',
                      style: TextStyle(
                        fontSize: 16.sp,
                        color: ColorConfig.text_label,
                      )),
                  const SizedBox(width: 10),
                  starRating(
                    rating: 10,
                    size: 25,
                  )
                ],
              ),
            ),
            const SizedBox(height: 10),
            Container(
              margin: const EdgeInsets.symmetric(
                horizontal: 15,
              ),
              padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 5),
              color: ColorConfig.white,
              child: MultiRowInput('请输入评价内容', (str) {
                print(str);
                controller.content = str;
              }, 150, TextEditingController(text: '')),
            ),
          ],
        ),
      ),
    );
  }

  Widget itemWidget() {
    return Container(
      margin: const EdgeInsets.symmetric(horizontal: 15, vertical: 10),
      padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 5),
      color: ColorConfig.white,
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            clipBehavior: Clip.hardEdge,
            decoration: const BoxDecoration(
              // border: Border.all(color: ColorConfig.app_main, width: .5),
              borderRadius: BorderRadius.all(Radius.circular(8)),
            ),
            child: Obx(() => LoadNetworkImageWidget(
                width: 80, height: 80, imageUrl: controller.item['pic'] ?? "")),
          ),
          const SizedBox(width: 15),
          Expanded(
            child: Container(
              height: 80,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  const SizedBox(height: 5),
                  Obx(() => Text(controller.item['title'] ?? "",
                      style: TextStyle(
                        fontSize: 16.sp,
                        color: ColorConfig.text_label,
                      ))),
                  Spacer(),
                  Row(
                    children: [
                      Obx(() => Text(controller.item['name'] ?? "",
                          style: TextStyle(
                            fontSize: 14.sp,
                            color: Color(0xFF5A5A5A),
                          ))),
                      if ((controller.item['name'] ?? "").length > 0)
                        const SizedBox(width: 15),
                      Obx(() => Text(controller.item['timer'] ?? "",
                          style: TextStyle(
                            fontSize: 14.sp,
                            color: Color(0xFF5A5A5A),
                          ))),
                      const SizedBox(width: 15),
                      Expanded(
                        child: Obx(() => Text(
                            (controller.item['price'] ?? "").toString() + "/次",
                            style: TextStyle(
                              fontSize: 14.sp,
                              color: Color(0xFF5A5A5A),
                            ))),
                      ),
                      Obx(() => Text('x${controller.item['num']}',
                          style: TextStyle(
                            fontSize: 14.sp,
                            color: Color(0xFF5A5A5A),
                          ))),
                    ],
                  ),
                  const SizedBox(height: 5),
                ],
              ),
            ),
          ),
        ],
      ),
    );
  }
}
